package com.yuhuihui.common.utils.excel.export.parameters;

import org.apache.poi.ss.usermodel.CellStyle;

import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * excel导出sheet参数
 *
 * @author yuhh
 * @date 2022-08-22 16:20:39
 */
public class ExcelExportSheetParameter<T> {

    /**
     * 数据列表
     */
    private List<T> dataList;

    /**
     * 表头名
     */
    private String[][] fieldNames;

    /**
     * 列对应表头的code，注意：顺序必须和表头名相同，其值为dataList中List<T>类型T的属性名
     */
    private String[] fieldCodes;

    /**
     * excel片区名
     */
    private String sheetName;

    /**
     * 需要替换的值
     */
    private Map<String, Map<Object, Object>> replaceInfo;

    /**
     * 需要合并的列对应的code
     */
    private String[] mergeLine;

    /**
     * 需要合并的行对应的code
     */
    private List<String[]> mergeRow;

    /**
     * 内容是否需要合并行，true：是；false：否
     */
    private Boolean contentRowMerger;

    /**
     * 内容是否需要合并列，true：是；false：否
     * 针对异步导出无效
     */
    private Boolean contentLineMerger;

    /**
     * 单元格格式
     */
    private CellStyle cellStyle;

    /**
     * 标题，位于第一行，自动合并单元格并居中
     */
    private String title;

    /**
     * 汇总信息，位于最后一行，自动合并单元格并左对齐
     */
    private String summary;

    public ExcelExportSheetParameter(List<T> dataList, String[][] fieldNames, String[] fieldCodes){
        this.dataList = dataList;
        this.fieldNames = fieldNames;
        this.fieldCodes = fieldCodes;
    }

    public ExcelExportSheetParameter(){

    }

    public List<T> getDataList() {
        return dataList;
    }

    public ExcelExportSheetParameter<T> setDataList(List<T> dataList) {
        this.dataList = dataList;
        return this;
    }

    public String[][] getFieldNames() {
        return fieldNames;
    }

    public ExcelExportSheetParameter<T> setFieldNames(String[][] fieldNames) {
        this.fieldNames = fieldNames;
        return this;
    }

    public String[] getFieldCodes() {
        return fieldCodes;
    }

    public ExcelExportSheetParameter<T> setFieldCodes(String[] fieldCodes) {
        this.fieldCodes = fieldCodes;
        return this;
    }

    public String getSheetName() {
        return sheetName;
    }

    public ExcelExportSheetParameter<T> setSheetName(String sheetName) {
        this.sheetName = sheetName;
        return this;
    }

    public Map<String, Map<Object, Object>> getReplaceInfo() {
        return replaceInfo;
    }

    public ExcelExportSheetParameter<T> setReplaceInfo(Map<String, Map<Object, Object>> replaceInfo) {
        this.replaceInfo = replaceInfo;
        return this;
    }

    public String[] getMergeLine() {
        return mergeLine;
    }

    public ExcelExportSheetParameter<T> setMergeLine(String[] mergeLine) {
        this.mergeLine = mergeLine;
        return this;
    }

    public List<String[]> getMergeRow() {
        return mergeRow;
    }

    public ExcelExportSheetParameter<T> setMergeRow(List<String[]> mergeRow) {
        this.mergeRow = mergeRow;
        return this;
    }

    public Boolean getContentRowMerger() {
        return Optional.ofNullable(contentRowMerger).orElse(false);
    }

    public ExcelExportSheetParameter<T> setContentRowMerger(Boolean contentRowMerger) {
        this.contentRowMerger = contentRowMerger;
        return this;
    }

    public Boolean getContentLineMerger() {
        return Optional.ofNullable(contentLineMerger).orElse(false);
    }

    public ExcelExportSheetParameter<T> setContentLineMerger(Boolean contentLineMerger) {
        this.contentLineMerger = contentLineMerger;
        return this;
    }

    public CellStyle getCellStyle() {
        return cellStyle;
    }

    public ExcelExportSheetParameter<T> setCellStyle(CellStyle cellStyle) {
        this.cellStyle = cellStyle;
        return this;
    }

    public String getTitle() {
        return title;
    }

    public ExcelExportSheetParameter<T> setTitle(String title) {
        this.title = title;
        return this;
    }

    public String getSummary() {
        return summary;
    }

    public ExcelExportSheetParameter<T> setSummary(String summary) {
        this.summary = summary;
        return this;
    }
}
